import java.util.Scanner;

public class demo04 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        long sum=sc.nextInt();
        long num=7%n;
        sum-=num;
        sum%=7;
        System.out.println(sum);
    }
}
